package com.s.rpc.channel;

import com.s.rpc.ServiceRegistry;
import com.s.rpc.serializer.Serializer;
import com.s.rpc.handler.RpcServerHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import lombok.Getter;
import lombok.Setter;

/**
 * @author ShenshenLuo
 * @email luoshenshen@buaa.edu.cn
 * @date 2025/5/11 13:54
 **/
@Setter
@Getter
public class ServerChannel extends ChannelInitializer<SocketChannel> {

    private ServiceRegistry serviceRegistry;

    private Serializer serializer;

    public ServerChannel(Serializer serializer, ServiceRegistry serviceRegistry) {
        this.serviceRegistry = serviceRegistry;
        this.serializer = serializer;
    }

    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();
        pipeline.addLast(new RpcServerHandler(serviceRegistry));
    }
}
